/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ipartek.formacion.gestformwww.controlador;

import com.ipartek.formacion.gestformwww.modelo.ModeloSMS;
import com.ipartek.formacion.gestformwww.modelo.beans.SMSEnvio;
import com.ipartek.formacion.gestformwww.modelo.beans.excepciones.GestorFormacionExcepcion;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Curso
 */
public class VisualizarInformeSms implements Accion {

    AccionFactory f;

    public AccionRouter ejecuta(HttpServlet servlet, HttpServletRequest request, HttpServletResponse response) {
        AccionRouter router = null;
        ModeloSMS mSms = (ModeloSMS) servlet.getServletContext().getAttribute("ModeloSMS");
        HttpSession session = request.getSession();
        ArrayList<SMSEnvio> alSmsEnvio = new ArrayList<SMSEnvio>();
        int idCon, idCan;
        Boolean logueado = (Boolean) session.getAttribute("usuario");
        if (logueado != null) {
            if (request.getParameter("CanId") != null && request.getParameter("ConId") != null) {
                idCon = Integer.parseInt(request.getParameter("ConId"));
                idCan = Integer.parseInt(request.getParameter("CanId"));
                try {
                    alSmsEnvio = mSms.listarSMSCandidato(idCon, idCan);
                } catch (GestorFormacionExcepcion ex) {
                    Logger.getLogger(VisualizarInformeSms.class.getName()).log(Level.SEVERE, null, ex);
                }
                router = new AccionRouter("principal", true);

                request.setAttribute("listasms", alSmsEnvio);
                request.setAttribute("contenido-candidato", "visualiza-candidato-sms");
            }
        }

        return router;
    }

    public void inicializa(AccionFactory factory) {
        this.f = factory;
    }
}
